import { defineConfig } from 'vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import vue from '@vitejs/plugin-vue'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(),
  Components({
    resolvers: [
      ElementPlusResolver({
        importStyle: "sass",
        // directives: true,
        // version: "2.1.5",
      }),
    ],
  }),
  AutoImport({
    resolvers: [
      ElementPlusResolver({
        importStyle: "sass",
        // directives: true,
        // version: "2.1.5",
      }),
    ],
  }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, "src")
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "@/theme/index.scss" as *;`,
      },
    },
  },
  base: "./",
  // 本地服务器启动和服务器代理
  server: {
    port: 8080,
    hmr: {
      host: '127.0.0.1',
      port: 8080
    },
    open: true,
    cors: true,//允许跨域,
    // 设置代理
    proxy: {
      // ‘/api’：是指遇到这个字符开头的话，在这个字符前面加上target里面的ip或者域名
      '/api': {
        target: "https://www.fastmock.site/mock/563c8243fdb59c061ec346ac816523a8/api",
        //  允许跨域请求
        changeOrigin: true,
        // 重写路径,
        rewrite: (path: string): string => path.replace(/^\/api/, "")
      }
    }
  }
})
